package acm;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Scanner;

public class PassMessage
{
	static Scanner in = new Scanner(System.in);
	PrintStream out = System.out;
	
	ArrayList<People> people;
	
	int start;
	int time;

	class People
	{
		int name;
		int time;
		boolean active;
		ArrayList<Connect> connect;
		
		public People(int name)
		{
			this.name = name;
			this.time = Integer.MAX_VALUE;
			active = true;
			connect = new ArrayList<Connect>();
		}
		
		public void add(Connect connect)
		{
			this.connect.add(connect);
		}
		
		public void destory()
		{
			active = false;
		}
		
		public void reactive()
		{
			this.time = Integer.MAX_VALUE;
			active = true;
		}
	}
	
	class Connect
	{
		People name;
		int time;
		
		public Connect(People name, int time)
		{
			this.name = name;
			this.time = time;
		}
	}
	
	public PassMessage(int numPeople)
	{
		people = new ArrayList<People>();
		
		start = 0;
		time = Integer.MAX_VALUE;
		
		for ( int i=0; i<numPeople; i++ )
		{
			people.add(new People(i));
		}
		
		for ( int i=0; i<numPeople; i++ )
		{
			for ( int j=in.nextInt(); j>0; j-- )
			{
				people.get(i).add(new Connect(people.get(in.nextInt() - 1), in.nextInt()));
			}
		}
	}
	
	public void figure(int numPeople)
	{
		for ( int i=0; i<numPeople; i++)
			sendMessage(i);
		
		if(time == Integer.MAX_VALUE)
			out.println("disjoint");
		else
			out.println(start + " " + time);
	}
	
	public void sendMessage(int start)
	{
		ArrayList<People> active = new ArrayList<People>();

		ArrayList<People> add;
		ArrayList<People> remove;
		
		for( People temp : people)
		{
			temp.reactive();
		}
		
		
		int time = 0;
		
		people.get(start).time = 0;
		active.add(people.get(start));
		
		while ( time < 1000 )
		{
			add = new ArrayList<People>();
			remove = new ArrayList<People>();
			
			for( People activePeople : active )
			{
				if ( time == activePeople.time )
				{
					for ( Connect connectTemp : activePeople.connect )
					{
						if ( connectTemp.name.active )
						{
							int tempTime = time + connectTemp.time;

							if ( tempTime < connectTemp.name.time )
							{
								connectTemp.name.time = tempTime;
							}
							
							if ( !active.contains( connectTemp.name ) )
							{
								add.add( connectTemp.name );
							}
						}
					}
					
					remove.add(activePeople);
					activePeople.destory();
				}
			}
			
			active.addAll(add);
			active.removeAll(remove);
			
			
			if ( active.size() == 0 )
			{
				boolean check = true;
				
				for( People temp : people )
				{
					if ( temp.active )
					{
						check = false;
						break;
					}
				}
				
				if( time < this.time && check )
				{
					this.start = start + 1;
					this.time = time;
				}
				
				break;
			}

			time++;
		}
	}
	
	public static void main(String[] args)
	{
		int i;
		
		while( (i = in.nextInt()) != 0 )
		{
			PassMessage pm = new PassMessage(i);
			
			pm.figure(i);
		}
	}
}
